package zpy.servlet.servlet;


import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebInitParam;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * Servlet implementation class WizzardCreateServlet
 */
@WebServlet(
		description = "利用向导创建Servlet", 
		urlPatterns = { "/wizzardCreateServlet" }, 
		initParams = { 
				@WebInitParam(name = "fileUploadPath", value = "D:\\upload", description = "文件上传路径"),
				@WebInitParam(name = "fileUploadUrl", value = "/fileUpload", description = "上传文件访问url")
		})
public class WizzardCreateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public WizzardCreateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("GET");
		String name = request.getParameter("name");
		String num = request.getParameter("num");
		request.setAttribute("method", "GET");
		request.setAttribute("name", name);
		request.setAttribute("num", num);
		ServletContext applicaton = getServletContext();
		RequestDispatcher dispatcher =
				applicaton.getRequestDispatcher("/WEB-INF/jsp/httpServletTestResult.jsp");
		dispatcher.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		String name = request.getParameter("name");
		String num = request.getParameter("num");
		
		request.setAttribute("method", "POST");
		request.setAttribute("name", name);
		request.setAttribute("num", num);
		ServletContext applicaton = getServletContext();
		RequestDispatcher dispatcher = 
				applicaton.getRequestDispatcher("/WEB-INF/jsp/httpServletTestResult.jsp");
		dispatcher.forward(request, response);
	}

}
